<!--
 * @Author: ZAL 2177624751@qq.com
 * @Date: 2025-03-31 21:30:00
 * @LastEditors: ZAL 2177624751@qq.com
 * @LastEditTime: 2025-03-31 21:29:23
 * @Description: 礼品卡页面
-->
<template>
  <view class="container">
    <!-- 礼品卡卡片 -->
    <view class="giftcard-card">
      <view class="giftcard-header">
        <text class="title">我的礼品卡</text>
        <text class="amount">￥{{ totalAmount }}</text>
      </view>
      <view class="giftcard-footer">
        <view class="footer-item">
          <text class="label">可使用</text>
          <text class="value">{{ availableCount }}张</text>
        </view>
        <view class="footer-item">
          <text class="label">已使用</text>
          <text class="value">{{ usedCount }}张</text>
        </view>
        <view class="footer-item">
          <text class="label">已过期</text>
          <text class="value">{{ expiredCount }}张</text>
        </view>
      </view>
    </view>

    <!-- 礼品卡列表 -->
    <view class="giftcard-list">
      <view class="section-title">礼品卡列表</view>
      <scroll-view 
        class="list-content" 
        scroll-y 
        @scrolltolower="loadMore"
        v-if="giftcardList.length > 0"
      >
        <view 
          class="giftcard-item" 
          v-for="item in giftcardList" 
          :key="item.id"
          :class="{ 'expired': item.status === 'expired' }"
        >
          <view class="item-left">
            <view class="amount-wrap">
              <text class="currency">￥</text>
              <text class="amount">{{ item.amount }}</text>
            </view>
            <text class="card-no">卡号：{{ item.cardNo }}</text>
          </view>
          <view class="item-right">
            <view class="info-wrap">
              <text class="title">{{ item.title }}</text>
              <text class="time">{{ item.validTime }}</text>
            </view>
            <text class="status">{{ item.statusText }}</text>
          </view>
        </view>
      </scroll-view>
      <view v-else class="empty-state">
        <image src="/static/images/empty-giftcard.png" mode="aspectFit" class="empty-image" />
        <text>暂无礼品卡</text>
      </view>
    </view>

    <!-- 使用规则 -->
    <view class="giftcard-rules">
      <view class="section-title">使用规则</view>
      <view class="rules-content">
        <view class="rule-item" v-for="(rule, index) in rules" :key="index">
          <text class="rule-title">{{ rule.title }}</text>
          <text class="rule-desc">{{ rule.desc }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 数据状态
const totalAmount = ref(0)
const availableCount = ref(0)
const usedCount = ref(0)
const expiredCount = ref(0)

const giftcardList = ref([
  {
    id: 1,
    amount: 100,
    cardNo: 'GC20250331001',
    title: '生日礼品卡',
    validTime: '2025-03-31 23:59:59',
    status: 'available',
    statusText: '可使用'
  },
  {
    id: 2,
    amount: 50,
    cardNo: 'GC20250331002',
    title: '节日礼品卡',
    validTime: '2025-03-31 23:59:59',
    status: 'used',
    statusText: '已使用'
  },
  {
    id: 3,
    amount: 200,
    cardNo: 'GC20250331003',
    title: '会员礼品卡',
    validTime: '2025-03-30 23:59:59',
    status: 'expired',
    statusText: '已过期'
  }
])

const rules = ref([
  {
    title: '使用条件',
    desc: '礼品卡可在购买商品时抵扣支付'
  },
  {
    title: '有效期',
    desc: '礼品卡有效期为激活后1年'
  },
  {
    title: '使用范围',
    desc: '礼品卡仅限购买水果商品使用'
  }
])

// 加载更多
const loadMore = () => {
  // TODO: 实现加载更多逻辑
}
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background-color: #f8f8f8;
  padding-bottom: env(safe-area-inset-bottom);
}

.giftcard-card {
  margin: 20rpx;
  padding: 40rpx;
  background: linear-gradient(135deg, #00b578, #07c160);
  border-radius: 20rpx;
  color: #fff;

  .giftcard-header {
    margin-bottom: 40rpx;

    .title {
      font-size: 28rpx;
      opacity: 0.9;
    }

    .amount {
      display: block;
      font-size: 60rpx;
      font-weight: bold;
      margin-top: 20rpx;
    }
  }

  .giftcard-footer {
    display: flex;
    justify-content: space-around;
    border-top: 1rpx solid rgba(255, 255, 255, 0.2);
    padding-top: 30rpx;

    .footer-item {
      text-align: center;

      .label {
        font-size: 24rpx;
        opacity: 0.9;
      }

      .value {
        display: block;
        font-size: 32rpx;
        font-weight: bold;
        margin-top: 10rpx;
      }
    }
  }
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  margin: 30rpx 20rpx 20rpx;
}

.giftcard-list {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 12rpx;
  padding: 20rpx;

  .list-content {
    height: 400rpx;
  }

  .giftcard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30rpx;
    margin-bottom: 20rpx;
    background: linear-gradient(135deg, #f0fff4, #fff);
    border-radius: 12rpx;
    border: 1rpx solid #b7eb8f;

    &.expired {
      opacity: 0.5;
      background: #f5f5f5;
      border-color: #ddd;
    }

    .item-left {
      .amount-wrap {
        display: flex;
        align-items: baseline;

        .currency {
          font-size: 32rpx;
          color: #00b578;
          font-weight: bold;
        }

        .amount {
          font-size: 48rpx;
          color: #00b578;
          font-weight: bold;
          margin-left: 4rpx;
        }
      }

      .card-no {
        font-size: 24rpx;
        color: #999;
        margin-top: 10rpx;
      }
    }

    .item-right {
      text-align: right;

      .info-wrap {
        margin-bottom: 10rpx;

        .title {
          font-size: 28rpx;
          color: #333;
          margin-bottom: 6rpx;
          display: block;
        }

        .time {
          font-size: 24rpx;
          color: #999;
        }
      }

      .status {
        font-size: 24rpx;
        color: #00b578;
      }
    }
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60rpx 0;

  .empty-image {
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 20rpx;
  }

  text {
    font-size: 28rpx;
    color: #999;
  }
}

.giftcard-rules {
  background-color: #fff;
  margin: 20rpx;
  border-radius: 12rpx;
  padding: 20rpx;

  .rules-content {
    .rule-item {
      margin-bottom: 30rpx;

      .rule-title {
        font-size: 28rpx;
        color: #333;
        font-weight: bold;
        margin-bottom: 10rpx;
        display: block;
      }

      .rule-desc {
        font-size: 24rpx;
        color: #666;
        line-height: 1.6;
      }
    }
  }
}
</style> 